package cn.net.gemai.springboot_quartz.jobs;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ConsoleJob extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        /**
         * 获取JobDetail中关联的数据
         * 每个JobDetail内都有一个Map，包含了关联到这个Job的数据，在Job类中可以通过context获取
         */
        String msg = (String) jobExecutionContext.getJobDetail().getJobDataMap().get("msg");

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("ConsoleJob----" + sdf.format(new Date()) + " " + msg);
    }
}
